package com.dm0858.bianmin.mine.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.bumptech.glide.Glide;
import com.dm0858.bianmin.R;
import com.dm0858.bianmin.mine.base.BaseRecyclerViewAdapter;
import com.dm0858.bianmin.mine.base.BaseViewHolder;
import com.dm0858.bianmin.mine.bean.MyReleaseBeanData;
import com.dm0858.bianmin.mine.tools.ShapeUtils;

import java.util.List;

public class MyReleaseRecyclerViewAdapter extends BaseRecyclerViewAdapter {

    private Context mContext;

    private List<MyReleaseBeanData.DataBean> list;

    /**
     * 构造方法
     *
     * @param mContext
     * @param resource
     * @param data
     */
    public MyReleaseRecyclerViewAdapter(Context mContext, int resource, List data) {
        super(mContext, resource, data);
        this.mContext = mContext;
        if (data != null) this.list = data;
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        MyReleaseBeanData.DataBean data = list.get(position);
        Glide.with(mContext).load(data.getImage()).into(holder.getImageView(R.id.img_picture));
        holder
                .setText(R.id.txt_title,data.getTitle())
                .setText(R.id.txt_area,data.getArea())
                .setText(R.id.txt_type,data.getSectionName())
                .setText(R.id.txt_date,data.getCreateDate())
                .setText(R.id.txt_status,setStatus(Integer.valueOf(data.getState())))
                .setTextColor(R.id.txt_status,setStatusTextColor(Integer.valueOf(data.getState())))
                .setTextBackground(R.id.txt_status,setStatusBackground(Integer.valueOf(data.getState())));
    }

    /**
     * 设置状态
     * @param status
     * @return
     */
    private String setStatus(int status) {
        String s = "审核中";
        switch (status) {
            case 0:
                s = "审核中";
                break;
            case 1:
                s = "审核成功";
                break;
            case 2:
                s = "审核失败";
                break;
            default:
                s = "审核中";
        }
        return s;
    }

    /**
     * 设置状态字体颜色
     * @param status
     * @return
     */
    private int setStatusTextColor(int status) {
        int color;
        switch (status) {
            case 0:
                color = mContext.getResources().getColor(R.color.appTheme,null);
                break;
            case 1:
            case 2:
                color = mContext.getResources().getColor(color = R.color.white,null);
                break;
            default:
                color = mContext.getResources().getColor(R.color.appTheme,null);
                break;
        }
        return color;
    }

    /**
     * 设置状态背景颜色
     * @param status
     * @return
     */
    private Drawable setStatusBackground(int status) {
        Drawable drawable;
        switch (status) {
            case 0:
                drawable = new ShapeUtils().corner(4).line(1,mContext.getResources().getColor(R.color.appTheme,null)).build();
                break;
            case 1:
                drawable = new ShapeUtils().corner(4).fill(mContext.getResources().getColor(R.color.appTheme,null)).build();
                break;
            case 2:
                drawable = new ShapeUtils().corner(4).fill(mContext.getResources().getColor(R.color.grey_500,null)).build();
                break;
            default:
                drawable = new ShapeUtils().corner(4).line(1,mContext.getResources().getColor(R.color.appTheme,null)).build();
            break;
        }
        return drawable;
    }


    @Override
    protected int getSize() {
        if (list == null) return 0;
        else return list.size();
    }
}
